import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:dio/dio.dart';
import '../../http/Api.dart';
import '../../http/HttpUtil.dart';
import '../../entity/MoneyEntity.dart';
import '../../util/AppSaveInfoUtil.dart';
import '../../base/Constant.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'TXPage.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_easyrefresh/material_header.dart';
import 'package:flutter_easyrefresh/material_footer.dart';
class MoneyListPage extends StatefulWidget {
  MoneyListPage({Key key}) : super(key: key);

  @override
  _MoneyListPageState createState() => _MoneyListPageState();
}

class _MoneyListPageState extends State<MoneyListPage> {
  List<MoneyEntity> articles = new List();
  int page = 1;
  String token = "";
  EasyRefreshController _controller = new EasyRefreshController();

      @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getString(TOKEN).then((value) {
      token = value;
      loadList();
    });
  }

  loadList() async {
    // FormData formData = new FormData.fromMap({
    //   "token": token,
    // });
    // Response<String> response =
    //     await HttpUtil().post(Api.DrawRecord, data: formData);
    // Map userMap = json.decode(response.data);
    // if (userMap['code'] == 0 && mounted) {
    //   articles.clear();
    //   // _easyRefreshKey.currentState.callRefreshFinish();
    //   _controller.finishRefresh();
    //   (userMap['data']['list'] as List).forEach((v) {
    //     articles.add(new MoneyEntity.fromJson(v));
    //   });
    //   setState(() {});
    // }
  }


  @override
  Widget build(BuildContext context) {
   // TODO: implement build
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(
          "提现记录",
          style: TextStyle(
              fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
              color: Colors.black),
        ),
        elevation: 0.5,
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        centerTitle: true,
        iconTheme: new IconThemeData(color: Colors.black),
        actions: <Widget>[
          GestureDetector(
            child: Container(
              alignment: Alignment.center,
              child: Text(
                '提现',
                style: TextStyle(
                    fontSize: ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE),
                    color: Colors.black54),
              ),
              padding: EdgeInsets.fromLTRB(0, 0, 15, 0),
            ),
            onTap: () {
               Navigator.of(context).push<String>(new MaterialPageRoute(builder:(context){
                  return new TXPage();
              })).then((value){
                if(value!=null){
                    loadList();
                }
              });
            },
          )
        ],
      ),
      body: new Container(
        color: divideColor,
        child: new EasyRefresh(
          controller: _controller,
          header: MaterialHeader(),
          footer: MaterialFooter(),
          child: ListView.separated(
              itemBuilder: _renderRow,
              separatorBuilder: (BuildContext context, int index) {
                return Container(
                  color: divideColor,
                  height: 1,
                );
              },
              itemCount: articles.length),
          onRefresh: () async {
            page = 1;
            loadList();
          },
          // loadMore: () async {
          //   page++;
          //   loadList();
          // },
        ),
      ),
    );
  }

  Widget _renderRow(BuildContext context, int index) {
    return new GestureDetector(
      onTap: () {
        // Navigator.of(context).push<String>(MaterialPageRoute(builder: (context) {
        //   return new AddShopNoticePage(
        //     entity: articles[index],
        //   );
        // })).then((value){
        //   if(value!=null){
        //     loadList();
        //   }
        // });
      },
      child: new Container(
        color: Colors.white,
        padding: EdgeInsets.all(15.0),
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            new Row(
              children: <Widget>[
                Expanded(
                  child: Text(
                    articles[index].action_zh,
                    style: TextStyle(
                        fontSize:
                            ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE),
                        color: Colors.black),
                  ),
                ),
                Text(
                  articles[index].action_symbol+articles[index].money,
                  style: TextStyle(
                      fontSize: ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE),
                      color: Colors.black54),
                )
              ],
            ),
            Container(
              padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
              child: Text(
                articles[index].create_time,
                style: TextStyle(
                    fontSize: ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE),
                    color: Colors.black54),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ],
        ),
      ),
    );
  }
}